import History from "./base";

class BrowserHistory extends History {
  constructor(router) {
    super(router);
  }

  // 监听history 模式的路由变化，并响应式更新视图
  setupListener() {
    window.addEventListener("popstate", () => {
      this.transitionTo(window.location.pathname);
    })
  }

  // 获取当前的路由路径
  getCurrentLocation() {
    return window.location.pathname
  }

  // 手动跳转路由
  push(location) {
    this.transitionTo(location, () => {
      history.pushState("", "", location);
    })
  }
}

export default BrowserHistory
